<?php
require_once 'database.php';
require_once 'common.php';

function getListOfStoriesForIteration(){

	$iterationId = isset($_GET['id']) ?htmlspecialchars($_GET['id']) : 0;

	//Get iterations for user
	$arrStories= array();

	$dbResult = mysql_query("SELECT * FROM story WHERE iteration_id= (SELECT iteration_id FROM iteration where iteration_id = '$iterationId')")
	or die("Problem reading table: " . mysql_error());

	while($row = mysql_fetch_array($dbResult)){
		$objStory = array();
		$objStory['story_name'] = $row['story_name'];
		$objStory['story_id'] = $row['story_id'];
	

		array_push($arrStories, $objStory);
	}

	return $arrStories;
}

function getListOfTasksForIteration(){
	$iterationId = isset($_GET['id']) ?htmlspecialchars($_GET['id']) : 0;
	
	$arrTasks = array();
	
	$dbResult = mysql_query("SELECT s.story_id, t.task_id, t.task_name FROM iteration i JOIN story s on i.iteration_id = s.iteration_id JOIN task t ON s.story_id = t.story_id WHERE i.iteration_id=$iterationId");

	while($row = mysql_fetch_array($dbResult)){
		$objTask = array();
		$objTask['story_id'] = $row['story_id'];
		$objTask['task_id'] = $row['task_id'];
		$objTask['task_name'] = $row['task_name'];
		
		array_push($arrTasks, $objTask);
	}
	
	return $arrTasks;
}